package org.ouwh.fw.model.module;

import org.ouwh.fw.util.xml.Node;

public abstract class Module {

	protected String id = null;

	protected String tagName = null;

	public Module() {
	}

	public Module(String tagName) {
		setTagName(tagName);
	}

	public String getId() {
		return id;
	}

	public String getTagName() {
		return tagName;
	}

	public void setId(String string) {
		id = string;
	}

	public void setTagName(String string) {
		tagName = string;
	}

	public String getNodeAttributeValue(Node aNode, String attrName) {
		try {
			return aNode.getXmlAttr(attrName).toString();
		} catch (Exception e) {
		}
		return null;
	}

	public void init(Node aNode) throws Exception {
		setId(getNodeAttributeValue(aNode, "id"));
		setTagName(aNode.getXmlType());
	}

	public String toString() {
		StringBuffer tmp = new StringBuffer();
		tmp.append('<');
		tmp.append(getTagName());
		if (getId() != null) {
			tmp.append(" id=\"");
			tmp.append(getId());
			tmp.append("\"/>");
		}
		return tmp.toString();
	}

}
